/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package core.threads.client.inGame;
import core.messages.client.inGame.Msg_Judge_Phase_End;
import core.messages.client.inGame.Msg_Judge_Require;
import core.threads.client.Client_Public_Data;
import core.threads.client.Client_Public_MsgBox;
import core.threads.client.Client_Public_Thread;
import models.Card.CardSpellBuff;
import models.Player;


/**
 *
 * @author Invince
 */
public class T_Client_Judge_Phase  extends Thread{
/*----------Attributs-------------------*/
    //protected boolean stop;
    protected boolean suspend;

/*----------Public functions------------*/
    @Override
    public void run() {
        /**-----Init-----**/
        String name;
        synchronized(Client_Public_Data.semaMyInfo){
            name=Client_Public_Data.myInfo.getName();
        }
        Player myInfo;
        synchronized(Client_Public_Data.semaMyInfo){
            myInfo=Client_Public_Data.myInfo;
        }
        Client_Public_Thread.tClientActiveSkill.resumeT();
        Client_Public_Data.myTurnBegin();//初始化所有轮次相关的共享信息，这个方法已经是synchronized的了
                
        /**-----main-----**/
        int sizeDeckBuff=myInfo.getDeckBuff().size();
        if(sizeDeckBuff==0){
            Client_Public_Thread.tClientDrawPhase=new T_Client_Draw_Phase();
            Client_Public_Thread.tClientDrawPhase.start();
        }else{            
                for(int i=0;i<sizeDeckBuff;i++){
                    CardSpellBuff cardBuff;
                    synchronized(Client_Public_Data.semaMyInfo){
                        cardBuff=(CardSpellBuff)Client_Public_Data.myInfo.getDeckBuff().get(0);//每次取的都是开头那张，每次在服务端都会把判定牌处理掉，再由screen消息发回来，所以DeckBuff每次都在减少
                    }
                    Msg_Judge_Require msgJudgeRequire=new Msg_Judge_Require(name,"Server", cardBuff.getJudgeType(), cardBuff.getId());
                    Client_Public_MsgBox.msgBox_Client_Send_Msg.offer(msgJudgeRequire);
                    this.suspendT();//这里不用semaphore了，suspendT已经是synchronized的了
                    while(!this.suspend){}
                }
        }
        /**----End-----**/
        Msg_Judge_Phase_End msgJudgePhaseEnd=new Msg_Judge_Phase_End(Client_Public_Data.myInfo.getName(),"Server");
        Client_Public_MsgBox.msgBox_Client_Send_Msg.offer(msgJudgePhaseEnd);
    }

//    public void stopT(){
//        synchronized(this){
//            this.stop=true;
//        }
//    }

    public void suspendT(){
        synchronized(this){
            this.suspend=true;
        }
    }

    public void resumeT(){
        synchronized(this){
            this.suspend=false;
        }
    }
/*----------Private functions-----------*/
/*----------Constructor-----------------*/
    public T_Client_Judge_Phase() {
        synchronized(this){
//            this.stop=false;
            this.suspend=false;
        }
    }
/*----------Gets and sets---------------*/
}
